package com.campus.mapper;

import com.campus.domain.entity.LostItemComment;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 失物评论Mapper
 */
@Mapper
public interface LostItemCommentMapper {
    
    // 插入评论
    @Insert("INSERT INTO lost_item_comments(item_id, user_id, content, like_count, reply_count) " +
            "VALUES(#{itemId}, #{userId}, #{content}, 0, 0)")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(LostItemComment comment);
    
    // 根据失物ID查询评论（分页）
    List<LostItemComment> selectByItemId(@Param("itemId") Long itemId, @Param("offset") Integer offset, @Param("limit") Integer limit);
    
    // 查询评论总数
    @Select("SELECT COUNT(*) FROM lost_item_comments WHERE item_id = #{itemId} AND is_deleted = 0")
    Long countByItemId(Long itemId);
    
    // 根据ID查询评论
    @Select("SELECT * FROM lost_item_comments WHERE id = #{id} AND is_deleted = 0")
    LostItemComment selectById(Long id);
    
    // 删除评论（逻辑删除）
    @Update("UPDATE lost_item_comments SET is_deleted = 1 WHERE id = #{id}")
    int deleteById(Long id);
    
    // 增加点赞数
    @Update("UPDATE lost_item_comments SET like_count = like_count + 1 WHERE id = #{id}")
    int incrementLikeCount(Long id);
    
    // 减少点赞数
    @Update("UPDATE lost_item_comments SET like_count = like_count - 1 WHERE id = #{id}")
    int decrementLikeCount(Long id);
    
    // 增加回复数
    @Update("UPDATE lost_item_comments SET reply_count = reply_count + 1 WHERE id = #{id}")
    int incrementReplyCount(Long id);
}

